Running the same script across multiple modules for metrics

Hello,

I created a script to gather data for metrics. Currently, I have to open each module to collect the data. How do I call the script to run for several modules w/o having to manually open and run it?

I would like to create essentially the same script to gather data for all modules per subsystem (w/ several modules each), and then call those subsystems from a system level script.

i.e.
SL consists of SS#1, SS#2, and SS#3
SS#1 has modules ss1A, ss1B, ss1C
SS#2 has modules ss2A, ss2B, ss2C, ss2D, ss2E
SS#3 has modules ss3A, ss3B

So I would like SS#1 to pull stats from only its modules when run, instead of having to access each one individually, and so on for SS#2 and SS#3.

And another script when ran at system level, SL, it would call the separated scripts for SS#1-3.

The reasoning behind all the separate subsystem scripts, is to provide them to each group, and the SL to run myself. I am assuming once I figure out how to do it once, then the same method will be used for the others.

ALSO, is there a way for the results to be displayed as a text file instead of just in the DXL Interaction GUI?

Thanks in advance!
SystemAdmin - Thu Jun 07 15:10:07 EDT 2012

Re: Running the same script across multiple modules for metrics
SystemAdmin - Thu Jun 07 15:11:16 EDT 2012

I didnt mean to strikeout the last statement ...

Is there a way for the results to be displayed as a text file instead of just in the DXL Interaction GUI?

Re: Running the same script across multiple modules for metrics
SystemAdmin - Thu Jun 07 16:32:53 EDT 2012

SystemAdmin - Thu Jun 07 15:11:16 EDT 2012
I didnt mean to strikeout the last statement ...

Is there a way for the results to be displayed as a text file instead of just in the DXL Interaction GUI?

about your 2nd question: see the DXL help file, Title: "Files and Streams".
You will find everything you need...

Re: Running the same script across multiple modules for metrics
SystemAdmin - Thu Jun 07 16:44:49 EDT 2012

I'm not completely sure about your needs, but I think you ask for a loop over all modules in a project or a range of folders.
Try the loop

Item i
for i in project "myproject" do {
   if "Formal" != type i then continue
   Module m = read (fullName i, false, true)
   …DoSomeStuff…
   close (m)
}

 


Have a look at the DXL help file, Titles "Items" and "Module manipulation".

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Mon Jun 11 15:20:08 EDT 2012

SystemAdmin - Thu Jun 07 16:44:49 EDT 2012

I'm not completely sure about your needs, but I think you ask for a loop over all modules in a project or a range of folders.
Try the loop

Item i
for i in project "myproject" do {
   if "Formal" != type i then continue
   Module m = read (fullName i, false, true)
   …DoSomeStuff…
   close (m)
}

 


Have a look at the DXL help file, Titles "Items" and "Module manipulation".

 

For question #1 ... is there way to call out specific modules, so I can potentially group by the subsystem, instead of looping through the entire project?

Q#2---
I looked into Streams and thought I figured it out using examples from the manual, but I keep outputting empty files (0KB).
 

string filename = tempFileName
print "Writing to " filename "\n"
Stream out = write filename
Buffer    bufResults = create()
 
Filter fShall = contains(attribute "Object Text", "shall")
set (mod, fShall, NumShall, xShall)
print "No. of 'shall' requirements: " NumShall "\n"
 
out << bufResults
close out
delete bufResults

 


I'm assuming my filter stats are not being gathered by the buffer and resulting in the empty output file, but not sure how to fix that. The print statement shows in the DXL Interaction GUI, how do I get it to print in the output file ???

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Mon Jun 11 17:26:07 EDT 2012

SystemAdmin - Mon Jun 11 15:20:08 EDT 2012

For question #1 ... is there way to call out specific modules, so I can potentially group by the subsystem, instead of looping through the entire project?

Q#2---
I looked into Streams and thought I figured it out using examples from the manual, but I keep outputting empty files (0KB).
 

string filename = tempFileName
print "Writing to " filename "\n"
Stream out = write filename
Buffer    bufResults = create()
 
Filter fShall = contains(attribute "Object Text", "shall")
set (mod, fShall, NumShall, xShall)
print "No. of 'shall' requirements: " NumShall "\n"
 
out << bufResults
close out
delete bufResults

 


I'm assuming my filter stats are not being gathered by the buffer and resulting in the empty output file, but not sure how to fix that. The print statement shows in the DXL Interaction GUI, how do I get it to print in the output file ???

 

About #1
Again I am not sure about your needs. What is a "subsystem" in your environment? How can you tell what subsystem a module belongs to?

If the subsystem is a part of the module name or of the name of a folder or sub-folder, you might want to check the "fullName" of the module (e.g. using a regular expression), before opening it.

If the subsystem is an attribute of the module, you might want to check the "ModuleProperties" of it before opening it. (a. see DXL help / b. beware the jabberwock memory leaks, see related posts in this forum)

Re: Running the same script across multiple modules for metrics
SystemAdmin - Mon Jun 11 17:43:07 EDT 2012

SystemAdmin - Mon Jun 11 15:20:08 EDT 2012

For question #1 ... is there way to call out specific modules, so I can potentially group by the subsystem, instead of looping through the entire project?

Q#2---
I looked into Streams and thought I figured it out using examples from the manual, but I keep outputting empty files (0KB).
 

string filename = tempFileName
print "Writing to " filename "\n"
Stream out = write filename
Buffer    bufResults = create()
 
Filter fShall = contains(attribute "Object Text", "shall")
set (mod, fShall, NumShall, xShall)
print "No. of 'shall' requirements: " NumShall "\n"
 
out << bufResults
close out
delete bufResults

 


I'm assuming my filter stats are not being gathered by the buffer and resulting in the empty output file, but not sure how to fix that. The print statement shows in the DXL Interaction GUI, how do I get it to print in the output file ???

 

About #2:
Sorry, you got it wrong ;-)

the statement "print" will always send an information to STDOUT (which usually is the DXL output window)

The Buffer you define is a storage place which "memorizes" the information, before it is actually given to wherever you send it to.

So, instead of (or … in addition to …)

print "No. of …"


try

 

bufResults += "No. of …"



This way the result will be written to the Buffer, which later is sent to the file (using the command "<<")

Of course, you could also completely omit the Buffer by just writing



 

 

out << "No. of …"

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Wed Jun 13 11:24:04 EDT 2012

SystemAdmin - Mon Jun 11 17:43:07 EDT 2012

About #2:
Sorry, you got it wrong ;-)

the statement "print" will always send an information to STDOUT (which usually is the DXL output window)

The Buffer you define is a storage place which "memorizes" the information, before it is actually given to wherever you send it to.

So, instead of (or … in addition to …)

print "No. of …"


try

 

bufResults += "No. of …"



This way the result will be written to the Buffer, which later is sent to the file (using the command "<<")

Of course, you could also completely omit the Buffer by just writing



 

 

out << "No. of …"

 

#2 ... thanks, adding 'out >>' and deleting the buffer worked great w/ one exception. I wanted to display the date and time as well but
 

Date d = dateAndTime(today)
print d
out << d

 


get errors for

 

 

out << d

 


I tried simplifying it and just stating

 

 

 

 

 

 

out << dataAndTime(today)


but it doesn't like that either :/

I definately don't NEED dxl to tell me the date and time, it's just a 'nice to have', but I am curious as to why it receives errors

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Wed Jun 13 14:17:14 EDT 2012

SystemAdmin - Wed Jun 13 11:24:04 EDT 2012

#2 ... thanks, adding 'out >>' and deleting the buffer worked great w/ one exception. I wanted to display the date and time as well but
 

Date d = dateAndTime(today)
print d
out << d

 


get errors for

 

 

out << d

 


I tried simplifying it and just stating

 

 

 

 

 

 

out << dataAndTime(today)


but it doesn't like that either :/

I definately don't NEED dxl to tell me the date and time, it's just a 'nice to have', but I am curious as to why it receives errors

 

Don't have access to a DOORS environment at the moment, but I think that the argument to "<<" on the right side should be of type string or Buffer or a number.

So, convert your date to a string (e.g. using the function stringOf) and output the result.

Re: Running the same script across multiple modules for metrics
llandale - Wed Jun 13 16:37:59 EDT 2012

SystemAdmin - Wed Jun 13 14:17:14 EDT 2012
Don't have access to a DOORS environment at the moment, but I think that the argument to "<<" on the right side should be of type string or Buffer or a number.

So, convert your date to a string (e.g. using the function stringOf) and output the result.

out << d ""

Re: Running the same script across multiple modules for metrics
SystemAdmin - Wed Jun 13 17:08:17 EDT 2012

SystemAdmin - Mon Jun 11 17:26:07 EDT 2012
About #1
Again I am not sure about your needs. What is a "subsystem" in your environment? How can you tell what subsystem a module belongs to?

If the subsystem is a part of the module name or of the name of a folder or sub-folder, you might want to check the "fullName" of the module (e.g. using a regular expression), before opening it.

If the subsystem is an attribute of the module, you might want to check the "ModuleProperties" of it before opening it. (a. see DXL help / b. beware the jabberwock memory leaks, see related posts in this forum)

#2 ... Thanks! ... it now shows the date in the output file :)
For #1

So I figured out how to code what I was trying to describe earlier, but I've come across a new problem. How do I call a separate script within my for loop?
 

for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
   }
}

 


How can I call my script and stream an output file that shows the data for each module found ... all streamed into 1 file, not a new file for each module?

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Wed Jun 13 17:11:10 EDT 2012

llandale - Wed Jun 13 16:37:59 EDT 2012
out << d ""

#2 ... Thanks! ... it now shows the date in the output file :)

For #1

So I figured out how to code what I was trying to describe earlier, but I've come across a new problem. How do I call a separate script within my for loop?

for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
   }
}

 


How can I call my script and stream an output file that shows the data for each module found ... all streamed into 1 file, not a new file for each module?

 

Re: Running the same script across multiple modules for metrics
SystemAdmin - Wed Jun 13 17:35:15 EDT 2012

SystemAdmin - Wed Jun 13 17:11:10 EDT 2012

#2 ... Thanks! ... it now shows the date in the output file :)

For #1

So I figured out how to code what I was trying to describe earlier, but I've come across a new problem. How do I call a separate script within my for loop?

for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
   }
}

 


How can I call my script and stream an output file that shows the data for each module found ... all streamed into 1 file, not a new file for each module?

 

Tried the following, but it creates a file that just shows the code of the dxl script (over and over again for each module), instead of actually executing it :(
 

string filename = tempFileName
print "Writing to ... " filename "\n\n"
Stream ofile = write filename
 
for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
       string results = readFile("C:\\.../Req Metrics.dxl") // not the actual path, deleted the details
       ofile << results 
    }
}
 
close(ofile)

 


I figure because I am just 'reading' the contents and not actually calling the script, but I'm not clear on how to call a script that I created that is not stored in the dxl library :|

 

Re: Running the same script across multiple modules for metrics
Martin_Hunter - Wed Jun 20 01:55:11 EDT 2012

SystemAdmin - Wed Jun 13 17:35:15 EDT 2012

Tried the following, but it creates a file that just shows the code of the dxl script (over and over again for each module), instead of actually executing it :(
 

string filename = tempFileName
print "Writing to ... " filename "\n\n"
Stream ofile = write filename
 
for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
       string results = readFile("C:\\.../Req Metrics.dxl") // not the actual path, deleted the details
       ofile << results 
    }
}
 
close(ofile)

 


I figure because I am just 'reading' the contents and not actually calling the script, but I'm not clear on how to call a script that I created that is not stored in the dxl library :|

 

I think the easiest solution would be to use the SmartDXL script "Run DXL on Selected Modules"

see http://www.smartdxl.com/content/?p=444

  • Martin

Re: Running the same script across multiple modules for metrics
Mathias Mamsch - Wed Jun 20 03:00:40 EDT 2012

SystemAdmin - Wed Jun 13 17:35:15 EDT 2012

Tried the following, but it creates a file that just shows the code of the dxl script (over and over again for each module), instead of actually executing it :(
 

string filename = tempFileName
print "Writing to ... " filename "\n\n"
Stream ofile = write filename
 
for i in flder do {
   if (type(i) == "Formal"){
       print fullName(i) "\n"
       // run my req metrics script(described in Q#2) 
       string results = readFile("C:\\.../Req Metrics.dxl") // not the actual path, deleted the details
       ofile << results 
    }
}
 
close(ofile)

 


I figure because I am just 'reading' the contents and not actually calling the script, but I'm not clear on how to call a script that I created that is not stored in the dxl library :|

 

You need to execute the script, not read its contents. For this you can use eval_. To redirect the output in case of print statements you would do a print redirection:
 

string sFileName = tempFileName()  // the output file
Stream stLog = write sFileName     // open the file 
 
// pass it to the eval_ context and make print write to it 
string sPrintRedirectionCode = "
Stream gPrintStream = addr_ " ((addr_ stLog) int) "
void print (Date d)         { gPrintStream << d \"\\n\"  ; flush gPrintStream } 
void print (string s)       { gPrintStream << s; flush gPrintStream }
void print (AttrBaseType ab){ gPrintStream << ab \"\\n\"; flush gPrintStream }
void print (int i)          { gPrintStream << i \"\\n\"  ; flush gPrintStream }
void print (char ch)        { gPrintStream << ch \"\\n\" ; flush gPrintStream }
void print (HistoryType ht) { gPrintStream << ht \"\\n\" ; flush gPrintStream }
void print (bool b)         { gPrintStream << b \"\\n\"  ; flush gPrintStream } 
void print (real r)         { gPrintStream << r \"\\n\"  ; flush gPrintStream }
"
 
// string sCode = = readFile("C:\\.../Req Metrics.dxl") // use your script for execution
string sCode = "print \"Hello World!\"" // use the script from readfile instead ...
 
eval_ sPrintRedirectionCode sCode
 
close stLog
 
print "Check the file " sFileName "\n"

 


Maybe that helps, regard, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS